from django.db import models, transaction

# Create your models here.

class ShortMessage(models.Model):
    id = models.AutoField(primary_key=True)
    messageId = models.CharField(max_length=100)
    phoneNumber = models.CharField(max_length=20)
    content = models.CharField(max_length=200)
    send_time = models.DateTimeField(auto_now=False, default=None)
    status = models.CharField(max_length=15, default=None)

    def __init__(self, *args, **kwargs):
        super(ShortMessage, self).__init__(*args, **kwargs)
    
    def __str__(self):
        return self.messageId
    
    def save(self, *args, **kwargs):
        return super(ShortMessage, self).save(*args, **kwargs)

    def delete(self):
        with transaction.atomic():
            super().delete()
    
def getById(id):
    return ShortMessage.objects.filter(id=id)

def getByMessageId(messageId):
    return ShortMessage.objects.filter(messageId=messageId)

def getList():
    return ShortMessage.objects.all()
